﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace School.WebPages.TeacheManage
{
    public partial class SubList : System.Web.UI.Page
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        protected string categoryStr = string.Empty;
        protected string parentCategoryStr = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            byte category = byte.Parse(Request.QueryString["categories"]);
            categoryStr = category.ToString();
            parentCategoryStr = Request.QueryString["parentCategory"];

            if (!Page.IsPostBack)
            {
                var mls = db.ModuleIntroduce;
                lt1.Text = mls.FirstOrDefault(m => m.Categories == 51).Introduce;
                lt2.Text = mls.FirstOrDefault(m => m.Categories == 52).Introduce;
                lt3.Text = mls.FirstOrDefault(m => m.Categories == 53).Introduce;

                int xqhz_totalArticles = db.Article.Where(a => a.SubMenu.Categories == 26 && a.IsChecked == 1 && a.IsEnabled == true).Count();
                anp_xqhz.RecordCount = xqhz_totalArticles;
                BindData();

                int jdjs_totalArticles = db.Article.Where(a => a.SubMenu.Categories == 27 && a.IsChecked == 1 && a.IsEnabled == true).Count();
                nap_jdjs.RecordCount = jdjs_totalArticles;
                jdjsBindData();
            }

        }

        private void BindData()
        {
            rep_xqhz.DataSource = DAL.PagerHelper.GetPagerData("Article", "ArticleID,Title,UpdateTime", "UpdateTime",
                anp_xqhz.PageSize, anp_xqhz.CurrentPageIndex, "Categories=26 and IsChecked=1 and IsEnabled=1");
            rep_xqhz.DataBind();
        }

        protected void anp_xqhz_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        private void jdjsBindData()
        {
            rep_jdjs.DataSource = DAL.PagerHelper.GetPagerData("Article", "ArticleID,Title,UpdateTime", "UpdateTime",
                nap_jdjs.PageSize, nap_jdjs.CurrentPageIndex, "Categories=27 and IsChecked=1 and IsEnabled=1");
            rep_jdjs.DataBind();
        }

        protected void nap_jdjs_PageChanged(object sender, EventArgs e)
        {
            jdjsBindData();
        }
    }
}
